package cn.jsu.oj.dispatchServer.satellite.netty.starter;

import cn.jsu.oj.dispatchServer.satellite.factory.Factory;
import cn.jsu.oj.dispatchServer.satellite.netty.NettyService;
import cn.jsu.oj.dispatchServer.satellite.util.TypeUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;

import java.util.concurrent.ExecutorService;

/**
 * 卫星起动器
 *
 * @author shan
 * @date 2022/07/07
 */
@Slf4j
@Component("satelliteStarter")
@DependsOn({"factoryConfig", "heartClientService"})
public class SatelliteStarter implements Starter, CommandLineRunner {

    @Autowired
    ExecutorService executorService;

    @Autowired
    Factory starterFactory;
    
    @Autowired
    NettyService nettyService;

    public static Boolean activeSign;

    public static Boolean verifySign;

    public SatelliteStarter() {
        activeSign = false;
        verifySign = false;
    }

    @Override
    public void run(String... args) {
//        nettyService.init();
       // start();
    }

    @Override
    public void start() {
        TypeUtil.objToMap(starterFactory.getProduct
                ((short) 0), Short.class, Starter.class)
                .forEach((key, value) -> 
                        executorService.execute(value::start));
    }
}
